package com.hbnu.iostream;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

/**
 * @author kittychen
 * @since 2025-10-13 17:25
 */
public class PrinterStreamDemo {
    public static void main(String[] args) {
        String path = "C:" + File.separator + "Users" + File.separator + "Administrator"
                + File.separator + "Desktop" + File.separator + "kittychen"
                + File.separator + "class2311" + File.separator + "printer.txt";
        File file = new File(path);

        PrintStream printStream = null;

        try {
            printStream = new PrintStream(new FileOutputStream(file));

            printStream.println("hello world");
            printStream.println("1+1 = " + 2);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (printStream != null) {
                printStream.close();
            }
        }
    }
}
